package com.wisedu.w5autocode.template;

import com.wisedu.w5autocode.views.*;

public class PortletXmlTemplate
{
  protected static String nl;
  public static synchronized PortletXmlTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    PortletXmlTemplate result = new PortletXmlTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "\t<portlet>" + NL + "\t\t<portlet-name>";
  protected final String TEXT_2 = "</portlet-name>" + NL + "\t\t<display-name>";
  protected final String TEXT_3 = "</display-name>" + NL + "\t\t<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>" + NL + "\t\t<init-param>" + NL + "\t\t\t<name>contextConfigLocation</name>" + NL + "\t\t\t<value>";
  protected final String TEXT_4 = "</value>" + NL + "\t\t</init-param>" + NL + "\t\t<supports>" + NL + "\t\t\t<mime-type>text/html</mime-type>" + NL + "\t\t\t<portlet-mode>view</portlet-mode>" + NL + "\t\t</supports>" + NL + "\t\t<portlet-info>" + NL + "\t\t\t<title>";
  protected final String TEXT_5 = "</title>" + NL + "\t\t</portlet-info>" + NL + "\t</portlet>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
	PortletXmlArgs args = (PortletXmlArgs)argument;

    stringBuffer.append(TEXT_1);
    stringBuffer.append(args.getPortletName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append(args.getTitle());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(args.getPortletConfigLocation());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(args.getTitle());
    stringBuffer.append(TEXT_5);
    return stringBuffer.toString();
  }
}
